package com.situ.cloud.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.situ.cloud.common.vo.RS;
import com.situ.cloud.user.entity.User;
import com.situ.cloud.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kkkkkk
 * @since 2023-10-24
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/list")
    public RS list(String username, String status, Integer currentPage, Integer pageSize) {
        List<User> list = userService.selectList(username, status, currentPage, pageSize);
        RS rs = RS.ok(list);
        rs.setCount(new PageInfo<>(list).getTotal());
        return rs;
    }

    @GetMapping("/selectByUsername")
    public User user(String username) {
        return userService.getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, username));
    }

}
